package it.unisalento.util;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtils {

	public static boolean isRightMonth(Calendar calendar, Date date){
		boolean retVal = false;
			Calendar calendar2= new GregorianCalendar();
			calendar2.setTime(date);
			if(calendar.get(Calendar.MONTH)==calendar2.get(Calendar.MONTH) &&
				calendar.get(Calendar.YEAR)==calendar2.get(Calendar.YEAR)){
				retVal=true;
			}
		return retVal;
	}
	
	public static int getDayFromDate(Date date){
		Calendar calendar2= new GregorianCalendar();
		calendar2.setTime(date);
		return calendar2.get(Calendar.DAY_OF_MONTH);
	}
	
	public static Calendar setCalendarTimeZero(Calendar calendar){
		Calendar retVal = calendar;
		
		retVal.set(Calendar.HOUR_OF_DAY,0);
		retVal.set(Calendar.MILLISECOND,0);
		retVal.set(Calendar.SECOND,0);
		retVal.set(Calendar.MINUTE,0);
		
		return retVal;
	}
	
	public static Calendar setDateTimeZero(Date date){
		Calendar retVal = new GregorianCalendar();
		retVal.setTime(date);
		return setCalendarTimeZero(retVal);
	}
}
